package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.Controller;

import model.Model;

public class ViewDialer extends JPanel {
	
	private Model model;
	private Controller controller;
	private JTextField ipField;
	private JTextField portField;
	
	
	public ViewDialer(Controller controller, int x, int y, int width, int height){
		this.controller=controller;
		this.model = controller.getModel();
		this.setBackground(Color.lightGray);
		this.setBounds(x,y,width,height);
		this.setLayout(new FlowLayout(FlowLayout.LEFT,0,5));
		
		JLabel labelIP = new JLabel("IP : ");
		labelIP.setPreferredSize(new Dimension(30, 30));
		this.add(labelIP);
	
		ipField = new JTextField();
        ipField.setPreferredSize(new Dimension(145, 30));
        this.add(ipField);
		
		JLabel labelPort = new JLabel("Port : ");
		labelPort.setPreferredSize(new Dimension(40, 30));

		this.add(labelPort);

		portField = new JTextField(this.model.getProperties().getProperty("tcp_port"));
		 portField.setPreferredSize(new Dimension(60, 30));
		 this.add(portField);
		 
		 JButton buttonSoundSetting = new JButton("Sound Setting");
		 buttonSoundSetting.setActionCommand("buttonSoundSetting");
		 buttonSoundSetting.addActionListener(this.controller);
		 this.add(buttonSoundSetting);
		 
		 JButton callButton = new JButton("Call");
		 callButton.setPreferredSize(new Dimension(298, 30));
		 callButton.setActionCommand("buttonCall");
		 callButton.addActionListener(this.controller);
		this.add(callButton);
		this.setVisible(false);
	}


	public void refresh() {
		//System.out.println("refreshViewDialer");
		portField.setText(this.model.getProperties().getProperty("tcp_port"));
		ipField.setText("");
		this.setVisible(this.model.getShowDialer());
		this.repaint();
		this.revalidate();
	}


	public JTextField getIpField() {
		return ipField;
	}


	public JTextField getPortField() {
		return portField;
	}

}
